<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>module ObjectSpace - objspace: Ruby Standard Library Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="module">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-allocation_class_path">::allocation_class_path</a>
    <li ><a href="#method-c-allocation_generation">::allocation_generation</a>
    <li ><a href="#method-c-allocation_method_id">::allocation_method_id</a>
    <li ><a href="#method-c-allocation_sourcefile">::allocation_sourcefile</a>
    <li ><a href="#method-c-allocation_sourceline">::allocation_sourceline</a>
    <li ><a href="#method-c-count_imemo_objects">::count_imemo_objects</a>
    <li ><a href="#method-c-count_nodes">::count_nodes</a>
    <li ><a href="#method-c-count_objects_size">::count_objects_size</a>
    <li ><a href="#method-c-count_symbols">::count_symbols</a>
    <li ><a href="#method-c-count_tdata_objects">::count_tdata_objects</a>
    <li ><a href="#method-c-internal_class_of">::internal_class_of</a>
    <li ><a href="#method-c-internal_super_of">::internal_super_of</a>
    <li ><a href="#method-c-memsize_of">::memsize_of</a>
    <li ><a href="#method-c-memsize_of_all">::memsize_of_all</a>
    <li ><a href="#method-c-reachable_objects_from">::reachable_objects_from</a>
    <li ><a href="#method-c-reachable_objects_from_root">::reachable_objects_from_root</a>
    <li ><a href="#method-c-trace_object_allocations">::trace_object_allocations</a>
    <li ><a href="#method-c-trace_object_allocations_clear">::trace_object_allocations_clear</a>
    <li ><a href="#method-c-trace_object_allocations_debug_start">::trace_object_allocations_debug_start</a>
    <li ><a href="#method-c-trace_object_allocations_start">::trace_object_allocations_start</a>
    <li ><a href="#method-c-trace_object_allocations_stop">::trace_object_allocations_stop</a>
    <li ><a href="#method-i-dump">#dump</a>
    <li ><a href="#method-i-dump_all">#dump_all</a>
    <li ><a href="#method-i-dump_shapes">#dump_shapes</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="module-ObjectSpace">
    <h1 id="module-ObjectSpace" class="module">
      module ObjectSpace
    </h1>

    <section class="description">
    
<p>The objspace library extends the <a href="ObjectSpace.html"><code>ObjectSpace</code></a> module and adds several methods to get internal statistic information about object/memory management.</p>

<p>You need to <code>require &#39;objspace&#39;</code> to use this extension module.</p>

<p>Generally, you <strong>SHOULD</strong> <strong>NOT</strong> use this library if you do not know about the MRI implementation.  Mainly, this library is for (memory) profiler developers and MRI developers who need to know about MRI memory usage.</p>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">





                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-allocation_class_path" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          allocation_class_path(object) &rarr; string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the class for the given <code>object</code>.</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">A</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">foo</span>
    <span class="ruby-constant">ObjectSpace</span><span class="ruby-operator">::</span><span class="ruby-identifier">trace_object_allocations</span> <span class="ruby-keyword">do</span>
      <span class="ruby-identifier">obj</span> = <span class="ruby-constant">Object</span>.<span class="ruby-identifier">new</span>
      <span class="ruby-identifier">p</span> <span class="ruby-node">&quot;#{ObjectSpace::allocation_class_path(obj)}&quot;</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>

<span class="ruby-constant">A</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">foo</span> <span class="ruby-comment">#=&gt; &quot;Class&quot;</span>
</pre>

<p>See <a href="ObjectSpace.html#method-c-trace_object_allocations"><code>::trace_object_allocations</code></a> for more information and examples.</p>

                              <div class="method-source-code" id="allocation_class_path-source">
            <pre>static VALUE
allocation_class_path(VALUE self, VALUE obj)
{
    struct allocation_info *info = lookup_allocation_info(obj);

    if (info &amp;&amp; info-&gt;class_path) {
        return rb_str_new2(info-&gt;class_path);
    }
    else {
        return Qnil;
    }
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-allocation_generation" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          allocation_generation(object) &rarr; integer or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns garbage collector generation for the given <code>object</code>.</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">B</span>
  <span class="ruby-identifier">include</span> <span class="ruby-constant">ObjectSpace</span>

  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">foo</span>
    <span class="ruby-identifier">trace_object_allocations</span> <span class="ruby-keyword">do</span>
      <span class="ruby-identifier">obj</span> = <span class="ruby-constant">Object</span>.<span class="ruby-identifier">new</span>
      <span class="ruby-identifier">p</span> <span class="ruby-node">&quot;Generation is #{allocation_generation(obj)}&quot;</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>

<span class="ruby-constant">B</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">foo</span> <span class="ruby-comment">#=&gt; &quot;Generation is 3&quot;</span>
</pre>

<p>See <a href="ObjectSpace.html#method-c-trace_object_allocations"><code>::trace_object_allocations</code></a> for more information and examples.</p>

                              <div class="method-source-code" id="allocation_generation-source">
            <pre>static VALUE
allocation_generation(VALUE self, VALUE obj)
{
    struct allocation_info *info = lookup_allocation_info(obj);
    if (info) {
        return SIZET2NUM(info-&gt;generation);
    }
    else {
        return Qnil;
    }
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-allocation_method_id" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          allocation_method_id(object) &rarr; string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the method identifier for the given <code>object</code>.</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">A</span>
  <span class="ruby-identifier">include</span> <span class="ruby-constant">ObjectSpace</span>

  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">foo</span>
    <span class="ruby-identifier">trace_object_allocations</span> <span class="ruby-keyword">do</span>
      <span class="ruby-identifier">obj</span> = <span class="ruby-constant">Object</span>.<span class="ruby-identifier">new</span>
      <span class="ruby-identifier">p</span> <span class="ruby-node">&quot;#{allocation_class_path(obj)}##{allocation_method_id(obj)}&quot;</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>

<span class="ruby-constant">A</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">foo</span> <span class="ruby-comment">#=&gt; &quot;Class#new&quot;</span>
</pre>

<p>See <a href="ObjectSpace.html#method-c-trace_object_allocations"><code>::trace_object_allocations</code></a> for more information and examples.</p>

                              <div class="method-source-code" id="allocation_method_id-source">
            <pre>static VALUE
allocation_method_id(VALUE self, VALUE obj)
{
    struct allocation_info *info = lookup_allocation_info(obj);
    if (info) {
        return info-&gt;mid;
    }
    else {
        return Qnil;
    }
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-allocation_sourcefile" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          allocation_sourcefile(object) &rarr; string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the source file origin from the given <code>object</code>.</p>

<p>See <a href="ObjectSpace.html#method-c-trace_object_allocations"><code>::trace_object_allocations</code></a> for more information and examples.</p>

                              <div class="method-source-code" id="allocation_sourcefile-source">
            <pre>static VALUE
allocation_sourcefile(VALUE self, VALUE obj)
{
    struct allocation_info *info = lookup_allocation_info(obj);

    if (info &amp;&amp; info-&gt;path) {
        return rb_str_new2(info-&gt;path);
    }
    else {
        return Qnil;
    }
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-allocation_sourceline" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          allocation_sourceline(object) &rarr; integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the original line from source for from the given <code>object</code>.</p>

<p>See <a href="ObjectSpace.html#method-c-trace_object_allocations"><code>::trace_object_allocations</code></a> for more information and examples.</p>

                              <div class="method-source-code" id="allocation_sourceline-source">
            <pre>static VALUE
allocation_sourceline(VALUE self, VALUE obj)
{
    struct allocation_info *info = lookup_allocation_info(obj);

    if (info) {
        return INT2FIX(info-&gt;line);
    }
    else {
        return Qnil;
    }
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-count_imemo_objects" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          count_imemo_objects([result_hash]) &rarr; hash
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Counts objects for each <code>T_IMEMO</code> type.</p>

<p>This method is only for MRI developers interested in performance and memory usage of Ruby programs.</p>

<p>It returns a hash as:</p>

<pre class="ruby">{<span class="ruby-value">:imemo_ifunc</span><span class="ruby-operator">=&gt;</span><span class="ruby-value">8</span>,
 <span class="ruby-value">:imemo_svar</span><span class="ruby-operator">=&gt;</span><span class="ruby-value">7</span>,
 <span class="ruby-value">:imemo_cref</span><span class="ruby-operator">=&gt;</span><span class="ruby-value">509</span>,
 <span class="ruby-value">:imemo_memo</span><span class="ruby-operator">=&gt;</span><span class="ruby-value">1</span>,
 <span class="ruby-value">:imemo_throw_data</span><span class="ruby-operator">=&gt;</span><span class="ruby-value">1</span>}
</pre>

<p>If the optional argument, result_hash, is given, it is overwritten and returned. This is intended to avoid probe effect.</p>

<p>The contents of the returned hash is implementation specific and may change in the future.</p>

<p>In this version, keys are symbol objects.</p>

<p>This method is only expected to work with C Ruby.</p>

                              <div class="method-source-code" id="count_imemo_objects-source">
            <pre>static VALUE
count_imemo_objects(int argc, VALUE *argv, VALUE self)
{
    VALUE hash = setup_hash(argc, argv);

    if (imemo_type_ids[0] == 0) {
#define INIT_IMEMO_TYPE_ID(n) (imemo_type_ids[n] = rb_intern_const(#n))
        INIT_IMEMO_TYPE_ID(imemo_env);
        INIT_IMEMO_TYPE_ID(imemo_cref);
        INIT_IMEMO_TYPE_ID(imemo_svar);
        INIT_IMEMO_TYPE_ID(imemo_throw_data);
        INIT_IMEMO_TYPE_ID(imemo_ifunc);
        INIT_IMEMO_TYPE_ID(imemo_memo);
        INIT_IMEMO_TYPE_ID(imemo_ment);
        INIT_IMEMO_TYPE_ID(imemo_iseq);
        INIT_IMEMO_TYPE_ID(imemo_tmpbuf);
        INIT_IMEMO_TYPE_ID(imemo_ast);
        INIT_IMEMO_TYPE_ID(imemo_parser_strterm);
        INIT_IMEMO_TYPE_ID(imemo_callinfo);
        INIT_IMEMO_TYPE_ID(imemo_callcache);
        INIT_IMEMO_TYPE_ID(imemo_constcache);
#undef INIT_IMEMO_TYPE_ID
    }

    each_object_with_flags(count_imemo_objects_i, (void *)hash);

    return hash;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-count_nodes" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          count_nodes([result_hash]) &rarr; hash
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Counts nodes for each node type.</p>

<p>This method is only for MRI developers interested in performance and memory usage of Ruby programs.</p>

<p>It returns a hash as:</p>

<pre>{:NODE_METHOD=&gt;2027, :NODE_FBODY=&gt;1927, :NODE_CFUNC=&gt;1798, ...}</pre>

<p>If the optional argument, result_hash, is given, it is overwritten and returned. This is intended to avoid probe effect.</p>

<p>Note: The contents of the returned hash is implementation defined. It may be changed in future.</p>

<p>This method is only expected to work with C Ruby.</p>

                              <div class="method-source-code" id="count_nodes-source">
            <pre>static VALUE
count_nodes(int argc, VALUE *argv, VALUE os)
{
    size_t nodes[NODE_LAST+1];
    enum node_type i;
    VALUE hash = setup_hash(argc, argv);

    for (i = 0; i &lt;= NODE_LAST; i++) {
        nodes[i] = 0;
    }

    each_object_with_flags(cn_i, &amp;nodes[0]);

    for (i=0; i&lt;NODE_LAST; i++) {
        if (nodes[i] != 0) {
            VALUE node;
            switch (i) {
#define COUNT_NODE(n) case n: node = ID2SYM(rb_intern(#n)); goto set
                COUNT_NODE(NODE_SCOPE);
                COUNT_NODE(NODE_BLOCK);
                COUNT_NODE(NODE_IF);
                COUNT_NODE(NODE_UNLESS);
                COUNT_NODE(NODE_CASE);
                COUNT_NODE(NODE_CASE2);
                COUNT_NODE(NODE_CASE3);
                COUNT_NODE(NODE_WHEN);
                COUNT_NODE(NODE_IN);
                COUNT_NODE(NODE_WHILE);
                COUNT_NODE(NODE_UNTIL);
                COUNT_NODE(NODE_ITER);
                COUNT_NODE(NODE_FOR);
                COUNT_NODE(NODE_FOR_MASGN);
                COUNT_NODE(NODE_BREAK);
                COUNT_NODE(NODE_NEXT);
                COUNT_NODE(NODE_REDO);
                COUNT_NODE(NODE_RETRY);
                COUNT_NODE(NODE_BEGIN);
                COUNT_NODE(NODE_RESCUE);
                COUNT_NODE(NODE_RESBODY);
                COUNT_NODE(NODE_ENSURE);
                COUNT_NODE(NODE_AND);
                COUNT_NODE(NODE_OR);
                COUNT_NODE(NODE_MASGN);
                COUNT_NODE(NODE_LASGN);
                COUNT_NODE(NODE_DASGN);
                COUNT_NODE(NODE_GASGN);
                COUNT_NODE(NODE_IASGN);
                COUNT_NODE(NODE_CDECL);
                COUNT_NODE(NODE_CVASGN);
                COUNT_NODE(NODE_OP_ASGN1);
                COUNT_NODE(NODE_OP_ASGN2);
                COUNT_NODE(NODE_OP_ASGN_AND);
                COUNT_NODE(NODE_OP_ASGN_OR);
                COUNT_NODE(NODE_OP_CDECL);
                COUNT_NODE(NODE_CALL);
                COUNT_NODE(NODE_OPCALL);
                COUNT_NODE(NODE_FCALL);
                COUNT_NODE(NODE_VCALL);
                COUNT_NODE(NODE_QCALL);
                COUNT_NODE(NODE_SUPER);
                COUNT_NODE(NODE_ZSUPER);
                COUNT_NODE(NODE_LIST);
                COUNT_NODE(NODE_ZLIST);
                COUNT_NODE(NODE_VALUES);
                COUNT_NODE(NODE_HASH);
                COUNT_NODE(NODE_RETURN);
                COUNT_NODE(NODE_YIELD);
                COUNT_NODE(NODE_LVAR);
                COUNT_NODE(NODE_DVAR);
                COUNT_NODE(NODE_GVAR);
                COUNT_NODE(NODE_IVAR);
                COUNT_NODE(NODE_CONST);
                COUNT_NODE(NODE_CVAR);
                COUNT_NODE(NODE_NTH_REF);
                COUNT_NODE(NODE_BACK_REF);
                COUNT_NODE(NODE_MATCH);
                COUNT_NODE(NODE_MATCH2);
                COUNT_NODE(NODE_MATCH3);
                COUNT_NODE(NODE_LIT);
                COUNT_NODE(NODE_STR);
                COUNT_NODE(NODE_DSTR);
                COUNT_NODE(NODE_XSTR);
                COUNT_NODE(NODE_DXSTR);
                COUNT_NODE(NODE_EVSTR);
                COUNT_NODE(NODE_DREGX);
                COUNT_NODE(NODE_ONCE);
                COUNT_NODE(NODE_ARGS);
                COUNT_NODE(NODE_ARGS_AUX);
                COUNT_NODE(NODE_OPT_ARG);
                COUNT_NODE(NODE_KW_ARG);
                COUNT_NODE(NODE_POSTARG);
                COUNT_NODE(NODE_ARGSCAT);
                COUNT_NODE(NODE_ARGSPUSH);
                COUNT_NODE(NODE_SPLAT);
                COUNT_NODE(NODE_BLOCK_PASS);
                COUNT_NODE(NODE_DEFN);
                COUNT_NODE(NODE_DEFS);
                COUNT_NODE(NODE_ALIAS);
                COUNT_NODE(NODE_VALIAS);
                COUNT_NODE(NODE_UNDEF);
                COUNT_NODE(NODE_CLASS);
                COUNT_NODE(NODE_MODULE);
                COUNT_NODE(NODE_SCLASS);
                COUNT_NODE(NODE_COLON2);
                COUNT_NODE(NODE_COLON3);
                COUNT_NODE(NODE_DOT2);
                COUNT_NODE(NODE_DOT3);
                COUNT_NODE(NODE_FLIP2);
                COUNT_NODE(NODE_FLIP3);
                COUNT_NODE(NODE_SELF);
                COUNT_NODE(NODE_NIL);
                COUNT_NODE(NODE_TRUE);
                COUNT_NODE(NODE_FALSE);
                COUNT_NODE(NODE_ERRINFO);
                COUNT_NODE(NODE_DEFINED);
                COUNT_NODE(NODE_POSTEXE);
                COUNT_NODE(NODE_DSYM);
                COUNT_NODE(NODE_ATTRASGN);
                COUNT_NODE(NODE_LAMBDA);
                COUNT_NODE(NODE_ARYPTN);
                COUNT_NODE(NODE_FNDPTN);
                COUNT_NODE(NODE_HSHPTN);
                COUNT_NODE(NODE_ERROR);
#undef COUNT_NODE
              case NODE_LAST: break;
            }
            UNREACHABLE;
          set:
            rb_hash_aset(hash, node, SIZET2NUM(nodes[i]));
        }
    }
    return hash;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-count_objects_size" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          count_objects_size([result_hash]) &rarr; hash
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Counts objects size (in bytes) for each type.</p>

<p>Note that this information is incomplete.  You need to deal with this information as only a <strong>HINT</strong>.  Especially, total size of T_DATA may be wrong.</p>

<p>It returns a hash as:</p>

<pre>{:TOTAL=&gt;1461154, :T_CLASS=&gt;158280, :T_MODULE=&gt;20672, :T_STRING=&gt;527249, ...}</pre>

<p>If the optional argument, result_hash, is given, it is overwritten and returned. This is intended to avoid probe effect.</p>

<p>The contents of the returned hash is implementation defined. It may be changed in future.</p>

<p>This method is only expected to work with C Ruby.</p>

                              <div class="method-source-code" id="count_objects_size-source">
            <pre>static VALUE
count_objects_size(int argc, VALUE *argv, VALUE os)
{
    size_t counts[T_MASK+1];
    size_t total = 0;
    enum ruby_value_type i;
    VALUE hash = setup_hash(argc, argv);

    for (i = 0; i &lt;= T_MASK; i++) {
        counts[i] = 0;
    }

    each_object_with_flags(cos_i, &amp;counts[0]);

    for (i = 0; i &lt;= T_MASK; i++) {
        if (counts[i]) {
            VALUE type = type2sym(i);
            total += counts[i];
            rb_hash_aset(hash, type, SIZET2NUM(counts[i]));
        }
    }
    rb_hash_aset(hash, ID2SYM(rb_intern(&quot;TOTAL&quot;)), SIZET2NUM(total));
    return hash;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-count_symbols" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          count_symbols([result_hash]) &rarr; hash
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Counts symbols for each Symbol type.</p>

<p>This method is only for MRI developers interested in performance and memory usage of Ruby programs.</p>

<p>If the optional argument, result_hash, is given, it is overwritten and returned. This is intended to avoid probe effect.</p>

<p>Note: The contents of the returned hash is implementation defined. It may be changed in future.</p>

<p>This method is only expected to work with C Ruby.</p>

<p>On this version of MRI, they have 3 types of Symbols (and 1 total counts).</p>

<pre>* mortal_dynamic_symbol: GC target symbols (collected by GC)
* immortal_dynamic_symbol: Immortal symbols promoted from dynamic symbols (do not collected by GC)
* immortal_static_symbol: Immortal symbols (do not collected by GC)
* immortal_symbol: total immortal symbols (immortal_dynamic_symbol+immortal_static_symbol)</pre>

                              <div class="method-source-code" id="count_symbols-source">
            <pre>static VALUE
count_symbols(int argc, VALUE *argv, VALUE os)
{
    struct dynamic_symbol_counts dynamic_counts = {0, 0};
    VALUE hash = setup_hash(argc, argv);

    size_t immortal_symbols = rb_sym_immortal_count();
    each_object_with_flags(cs_i, &amp;dynamic_counts);

    rb_hash_aset(hash, ID2SYM(rb_intern(&quot;mortal_dynamic_symbol&quot;)),   SIZET2NUM(dynamic_counts.mortal));
    rb_hash_aset(hash, ID2SYM(rb_intern(&quot;immortal_dynamic_symbol&quot;)), SIZET2NUM(dynamic_counts.immortal));
    rb_hash_aset(hash, ID2SYM(rb_intern(&quot;immortal_static_symbol&quot;)),  SIZET2NUM(immortal_symbols - dynamic_counts.immortal));
    rb_hash_aset(hash, ID2SYM(rb_intern(&quot;immortal_symbol&quot;)),         SIZET2NUM(immortal_symbols));

    return hash;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-count_tdata_objects" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          count_tdata_objects([result_hash]) &rarr; hash
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Counts objects for each <code>T_DATA</code> type.</p>

<p>This method is only for MRI developers interested in performance and memory usage of Ruby programs.</p>

<p>It returns a hash as:</p>

<pre class="ruby">{<span class="ruby-constant">RubyVM</span><span class="ruby-operator">::</span><span class="ruby-constant">InstructionSequence</span><span class="ruby-operator">=&gt;</span><span class="ruby-value">504</span>, <span class="ruby-value">:parser</span><span class="ruby-operator">=&gt;</span><span class="ruby-value">5</span>, <span class="ruby-value">:barrier</span><span class="ruby-operator">=&gt;</span><span class="ruby-value">6</span>,
 <span class="ruby-value">:mutex</span><span class="ruby-operator">=&gt;</span><span class="ruby-value">6</span>, <span class="ruby-constant">Proc</span><span class="ruby-operator">=&gt;</span><span class="ruby-value">60</span>, <span class="ruby-constant">RubyVM</span><span class="ruby-operator">::</span><span class="ruby-constant">Env</span><span class="ruby-operator">=&gt;</span><span class="ruby-value">57</span>, <span class="ruby-constant">Mutex</span><span class="ruby-operator">=&gt;</span><span class="ruby-value">1</span>, <span class="ruby-constant">Encoding</span><span class="ruby-operator">=&gt;</span><span class="ruby-value">99</span>,
 <span class="ruby-constant">ThreadGroup</span><span class="ruby-operator">=&gt;</span><span class="ruby-value">1</span>, <span class="ruby-constant">Binding</span><span class="ruby-operator">=&gt;</span><span class="ruby-value">1</span>, <span class="ruby-constant">Thread</span><span class="ruby-operator">=&gt;</span><span class="ruby-value">1</span>, <span class="ruby-constant">RubyVM</span><span class="ruby-operator">=&gt;</span><span class="ruby-value">1</span>, <span class="ruby-value">:iseq</span><span class="ruby-operator">=&gt;</span><span class="ruby-value">1</span>,
 <span class="ruby-constant">Random</span><span class="ruby-operator">=&gt;</span><span class="ruby-value">1</span>, <span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">class</span><span class="ruby-operator">=&gt;</span><span class="ruby-value">1</span>, <span class="ruby-constant">Data</span><span class="ruby-operator">=&gt;</span><span class="ruby-value">1</span>, <span class="ruby-value">:autoload</span><span class="ruby-operator">=&gt;</span><span class="ruby-value">3</span>, <span class="ruby-constant">Time</span><span class="ruby-operator">=&gt;</span><span class="ruby-value">2</span>}
<span class="ruby-comment"># T_DATA objects existing at startup on r32276.</span>
</pre>

<p>If the optional argument, result_hash, is given, it is overwritten and returned. This is intended to avoid probe effect.</p>

<p>The contents of the returned hash is implementation specific and may change in the future.</p>

<p>In this version, keys are Class object or Symbol object.</p>

<p>If object is kind of normal (accessible) object, the key is Class object. If object is not a kind of normal (internal) object, the key is symbol name, registered by rb_data_type_struct.</p>

<p>This method is only expected to work with C Ruby.</p>

                              <div class="method-source-code" id="count_tdata_objects-source">
            <pre>static VALUE
count_tdata_objects(int argc, VALUE *argv, VALUE self)
{
    VALUE hash = setup_hash(argc, argv);
    each_object_with_flags(cto_i, (void *)hash);
    return hash;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-internal_class_of" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          internal_class_of(obj) &rarr; Class or Module
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <dl class="rdoc-list label-list"><dt>MRI specific feature
<dd>
<p>Return internal class of obj.</p>
</dd></dl>

<p>obj can be an instance of <a href="ObjectSpace/InternalObjectWrapper.html"><code>InternalObjectWrapper</code></a>.</p>

<p>Note that you should not use this method in your application.</p>

                              <div class="method-source-code" id="internal_class_of-source">
            <pre>static VALUE
objspace_internal_class_of(VALUE self, VALUE obj)
{
    VALUE klass;

    if (rb_typeddata_is_kind_of(obj, &amp;iow_data_type)) {
        obj = (VALUE)DATA_PTR(obj);
    }

    if (RB_TYPE_P(obj, T_IMEMO)) {
        return Qnil;
    }
    else {
        klass = CLASS_OF(obj);
        return wrap_klass_iow(klass);
    }
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-internal_super_of" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          internal_super_of(cls) &rarr; Class or Module
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <dl class="rdoc-list label-list"><dt>MRI specific feature
<dd>
<p>Return internal super class of cls (Class or Module).</p>
</dd></dl>

<p>obj can be an instance of <a href="ObjectSpace/InternalObjectWrapper.html"><code>InternalObjectWrapper</code></a>.</p>

<p>Note that you should not use this method in your application.</p>

                              <div class="method-source-code" id="internal_super_of-source">
            <pre>static VALUE
objspace_internal_super_of(VALUE self, VALUE obj)
{
    VALUE super;

    if (rb_typeddata_is_kind_of(obj, &amp;iow_data_type)) {
        obj = (VALUE)DATA_PTR(obj);
    }

    switch (OBJ_BUILTIN_TYPE(obj)) {
      case T_MODULE:
      case T_CLASS:
      case T_ICLASS:
        super = RCLASS_SUPER(obj);
        break;
      default:
        rb_raise(rb_eArgError, &quot;class or module is expected&quot;);
    }

    return wrap_klass_iow(super);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-memsize_of" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          memsize_of(obj) &rarr; Integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Return consuming memory size of obj in bytes.</p>

<p>Note that the return size is incomplete.  You need to deal with this information as only a <strong>HINT</strong>. Especially, the size of <code>T_DATA</code> may not be correct.</p>

<p>This method is only expected to work with C Ruby.</p>

<p>From Ruby 2.2, <a href="ObjectSpace.html#method-c-memsize_of"><code>memsize_of</code></a>(obj) returns a memory size includes sizeof(RVALUE).</p>

                              <div class="method-source-code" id="memsize_of-source">
            <pre>static VALUE
memsize_of_m(VALUE self, VALUE obj)
{
    return SIZET2NUM(rb_obj_memsize_of(obj));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-memsize_of_all" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          memsize_of_all([klass]) &rarr; Integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Return consuming memory size of all living objects in bytes.</p>

<p>If <code>klass</code> (should be Class object) is given, return the total memory size of instances of the given class.</p>

<p>Note that the returned size is incomplete. You need to deal with this information as only a <strong>HINT</strong>. Especially, the size of <code>T_DATA</code> may not be correct.</p>

<p>Note that this method does <strong>NOT</strong> return total malloc’ed memory size.</p>

<p>This method can be defined by the following Ruby code:</p>

<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">memsize_of_all</span> <span class="ruby-identifier">klass</span> = <span class="ruby-keyword">false</span>
  <span class="ruby-identifier">total</span> = <span class="ruby-value">0</span>
  <span class="ruby-constant">ObjectSpace</span>.<span class="ruby-identifier">each_object</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">total</span> <span class="ruby-operator">+=</span> <span class="ruby-constant">ObjectSpace</span>.<span class="ruby-identifier">memsize_of</span>(<span class="ruby-identifier">e</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">klass</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">false</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-identifier">klass</span>)
  }
  <span class="ruby-identifier">total</span>
<span class="ruby-keyword">end</span>
</pre>

<p>This method is only expected to work with C Ruby.</p>

                              <div class="method-source-code" id="memsize_of_all-source">
            <pre>static VALUE
memsize_of_all_m(int argc, VALUE *argv, VALUE self)
{
    struct total_data data = {0, 0};

    if (argc &gt; 0) {
        rb_scan_args(argc, argv, &quot;01&quot;, &amp;data.klass);
    }

    each_object_with_flags(total_i, &amp;data);
    return SIZET2NUM(data.total);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-reachable_objects_from" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          reachable_objects_from(obj) &rarr; array or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <dl class="rdoc-list label-list"><dt>MRI specific feature
<dd>
<p>Return all reachable objects from ‘obj’.</p>
</dd></dl>

<p>This method returns all reachable objects from ‘obj’.</p>

<p>If ‘obj’ has two or more references to the same object ‘x’, then returned array only includes one ‘x’ object.</p>

<p>If ‘obj’ is a non-markable (non-heap management) object such as true, false, nil, symbols and Fixnums (and Flonum) then it simply returns nil.</p>

<p>If ‘obj’ has references to an internal object, then it returns instances of <a href="ObjectSpace/InternalObjectWrapper.html"><code>ObjectSpace::InternalObjectWrapper</code></a> class. This object contains a reference to an internal object and you can check the type of internal object with ‘type’ method.</p>

<p>If ‘obj’ is instance of <a href="ObjectSpace/InternalObjectWrapper.html"><code>ObjectSpace::InternalObjectWrapper</code></a> class, then this method returns all reachable object from an internal object, which is pointed by ‘obj’.</p>

<p>With this method, you can find memory leaks.</p>

<p>This method is only expected to work except with C Ruby.</p>

<p>Example:</p>

<pre class="ruby"><span class="ruby-constant">ObjectSpace</span>.<span class="ruby-identifier">reachable_objects_from</span>([<span class="ruby-string">&#39;a&#39;</span>, <span class="ruby-string">&#39;b&#39;</span>, <span class="ruby-string">&#39;c&#39;</span>])
<span class="ruby-comment">#=&gt; [Array, &#39;a&#39;, &#39;b&#39;, &#39;c&#39;]</span>

<span class="ruby-constant">ObjectSpace</span>.<span class="ruby-identifier">reachable_objects_from</span>([<span class="ruby-string">&#39;a&#39;</span>, <span class="ruby-string">&#39;a&#39;</span>, <span class="ruby-string">&#39;a&#39;</span>])
<span class="ruby-comment">#=&gt; [Array, &#39;a&#39;, &#39;a&#39;, &#39;a&#39;] # all &#39;a&#39; strings have different object id</span>

<span class="ruby-constant">ObjectSpace</span>.<span class="ruby-identifier">reachable_objects_from</span>([<span class="ruby-identifier">v</span> = <span class="ruby-string">&#39;a&#39;</span>, <span class="ruby-identifier">v</span>, <span class="ruby-identifier">v</span>])
<span class="ruby-comment">#=&gt; [Array, &#39;a&#39;]</span>

<span class="ruby-constant">ObjectSpace</span>.<span class="ruby-identifier">reachable_objects_from</span>(<span class="ruby-value">1</span>)
<span class="ruby-comment">#=&gt; nil # 1 is not markable (heap managed) object</span>
</pre>

                              <div class="method-source-code" id="reachable_objects_from-source">
            <pre>static VALUE
reachable_objects_from(VALUE self, VALUE obj)
{
    if (rb_objspace_markable_object_p(obj)) {
        struct rof_data data;

        if (rb_typeddata_is_kind_of(obj, &amp;iow_data_type)) {
            obj = (VALUE)DATA_PTR(obj);
        }

        data.refs = rb_obj_hide(rb_ident_hash_new());
        data.values = rb_ary_new();

        rb_objspace_reachable_objects_from(obj, reachable_object_from_i, &amp;data);

        return data.values;
    }
    else {
        return Qnil;
    }
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-reachable_objects_from_root" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          reachable_objects_from_root &rarr; hash
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <dl class="rdoc-list label-list"><dt>MRI specific feature
<dd>
<p>Return all reachable objects from root.</p>
</dd></dl>

                              <div class="method-source-code" id="reachable_objects_from_root-source">
            <pre>static VALUE
reachable_objects_from_root(VALUE self)
{
    struct rofr_data data;
    VALUE hash = data.categories = rb_ident_hash_new();
    data.last_category = 0;

    rb_objspace_reachable_objects_from_root(reachable_object_from_root_i, &amp;data);
    rb_hash_foreach(hash, collect_values_of_values, hash);

    return hash;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-trace_object_allocations" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          trace_object_allocations { block }
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Starts tracing object allocations from the <a href="ObjectSpace.html"><code>ObjectSpace</code></a> extension module.</p>

<p>For example:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;objspace&#39;</span>

<span class="ruby-keyword">class</span> <span class="ruby-constant">C</span>
  <span class="ruby-identifier">include</span> <span class="ruby-constant">ObjectSpace</span>

  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">foo</span>
    <span class="ruby-identifier">trace_object_allocations</span> <span class="ruby-keyword">do</span>
      <span class="ruby-identifier">obj</span> = <span class="ruby-constant">Object</span>.<span class="ruby-identifier">new</span>
      <span class="ruby-identifier">p</span> <span class="ruby-node">&quot;#{allocation_sourcefile(obj)}:#{allocation_sourceline(obj)}&quot;</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>

<span class="ruby-constant">C</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">foo</span> <span class="ruby-comment">#=&gt; &quot;objtrace.rb:8&quot;</span>
</pre>

<p>This example has included the <a href="ObjectSpace.html"><code>ObjectSpace</code></a> module to make it easier to read, but you can also use the <a href="ObjectSpace.html#method-c-trace_object_allocations"><code>::trace_object_allocations</code></a> notation (recommended).</p>

<p>Note that this feature introduces a huge performance decrease and huge memory consumption.</p>

                              <div class="method-source-code" id="trace_object_allocations-source">
            <pre>static VALUE
trace_object_allocations(VALUE self)
{
    trace_object_allocations_start(self);
    return rb_ensure(rb_yield, Qnil, trace_object_allocations_stop, self);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-trace_object_allocations_clear" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          trace_object_allocations_clear
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Clear recorded tracing information.</p>

                              <div class="method-source-code" id="trace_object_allocations_clear-source">
            <pre>static VALUE
trace_object_allocations_clear(VALUE self)
{
    struct traceobj_arg *arg = get_traceobj_arg();

    /* clear tables */
    st_foreach(arg-&gt;object_table, free_values_i, 0);
    st_clear(arg-&gt;object_table);
    st_foreach(arg-&gt;str_table, free_keys_i, 0);
    st_clear(arg-&gt;str_table);

    /* do not touch TracePoints */

    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-trace_object_allocations_debug_start" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">trace_object_allocations_debug_start</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="trace_object_allocations_debug_start-source">
            <pre>static VALUE
trace_object_allocations_debug_start(VALUE self)
{
    tmp_keep_remains = 1;
    if (object_allocations_reporter_registered == 0) {
        object_allocations_reporter_registered = 1;
        rb_bug_reporter_add(object_allocations_reporter, 0);
    }

    return trace_object_allocations_start(self);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-trace_object_allocations_start" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          trace_object_allocations_start
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Starts tracing object allocations.</p>

                              <div class="method-source-code" id="trace_object_allocations_start-source">
            <pre>static VALUE
trace_object_allocations_start(VALUE self)
{
    struct traceobj_arg *arg = get_traceobj_arg();

    if (arg-&gt;running++ &gt; 0) {
        /* do nothing */
    }
    else {
        if (arg-&gt;newobj_trace == 0) {
            arg-&gt;newobj_trace = rb_tracepoint_new(0, RUBY_INTERNAL_EVENT_NEWOBJ, newobj_i, arg);
            arg-&gt;freeobj_trace = rb_tracepoint_new(0, RUBY_INTERNAL_EVENT_FREEOBJ, freeobj_i, arg);
        }
        rb_tracepoint_enable(arg-&gt;newobj_trace);
        rb_tracepoint_enable(arg-&gt;freeobj_trace);
    }

    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-trace_object_allocations_stop" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          trace_object_allocations_stop
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Stop tracing object allocations.</p>

<p>Note that if <a href="ObjectSpace.html#method-c-trace_object_allocations_start"><code>::trace_object_allocations_start</code></a> is called n-times, then tracing will stop after calling <a href="ObjectSpace.html#method-c-trace_object_allocations_stop"><code>::trace_object_allocations_stop</code></a> n-times.</p>

                              <div class="method-source-code" id="trace_object_allocations_stop-source">
            <pre>static VALUE
trace_object_allocations_stop(VALUE self)
{
    struct traceobj_arg *arg = get_traceobj_arg();

    if (arg-&gt;running &gt; 0) {
        arg-&gt;running--;
    }

    if (arg-&gt;running == 0) {
        if (arg-&gt;newobj_trace != 0) {
            rb_tracepoint_disable(arg-&gt;newobj_trace);
        }
        if (arg-&gt;freeobj_trace != 0) {
            rb_tracepoint_disable(arg-&gt;freeobj_trace);
        }
    }

    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-dump" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">dump</span><span
                                class="method-args">(obj, output: :string)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Dump the contents of a ruby object as JSON.</p>

<p><em>output</em> can be one of: <code>:stdout</code>, <code>:file</code>, <code>:string</code>, or IO object.</p>
<ul><li>
<p><code>:file</code> means dumping to a tempfile and returning corresponding File object;</p>
</li><li>
<p><code>:stdout</code> means printing the dump and returning <code>nil</code>;</p>
</li><li>
<p><code>:string</code> means returning a string with the dump;</p>
</li><li>
<p>if an instance of IO object is provided, the output goes there, and the object is returned.</p>
</li></ul>

<p>This method is only expected to work with C Ruby. This is an experimental method and is subject to change. In particular, the function signature and output format are not guaranteed to be compatible in future versions of ruby.</p>

                              <div class="method-source-code" id="dump-source">
            <pre><span class="ruby-comment"># File objspace/lib/objspace.rb, line 28</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">dump</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-value">output:</span> <span class="ruby-value">:string</span>)
  <span class="ruby-identifier">out</span> = <span class="ruby-keyword">case</span> <span class="ruby-identifier">output</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">:file</span>, <span class="ruby-keyword">nil</span>
    <span class="ruby-identifier">require</span> <span class="ruby-string">&#39;tempfile&#39;</span>
    <span class="ruby-constant">Tempfile</span>.<span class="ruby-identifier">create</span>(<span class="ruby-node">%w(rubyobj .json)</span>)
  <span class="ruby-keyword">when</span> <span class="ruby-value">:stdout</span>
    <span class="ruby-constant">STDOUT</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">:string</span>
    <span class="ruby-string">+&#39;&#39;</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">IO</span>
    <span class="ruby-identifier">output</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;wrong output option: #{output.inspect}&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">ret</span> = <span class="ruby-identifier">_dump</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-identifier">out</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">output</span> <span class="ruby-operator">==</span> <span class="ruby-value">:stdout</span>
  <span class="ruby-identifier">ret</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-dump_all" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">dump_all</span><span
                                class="method-args">(output: :file, full: false, since: nil, shapes: true)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Dump the contents of the ruby heap as JSON.</p>

<p><em>output</em> argument is the same as for <a href="ObjectSpace.html#method-i-dump"><code>dump</code></a>.</p>

<p><em>full</em> must be a boolean. If true, all heap slots are dumped including the empty ones (<code>T_NONE</code>).</p>

<p><em>since</em> must be a non-negative integer or <code>nil</code>.</p>

<p>If <em>since</em> is a positive integer, only objects of that generation and newer generations are dumped. The current generation can be accessed using GC::count. Objects that were allocated without object allocation tracing enabled are ignored. See <a href="ObjectSpace.html#method-c-trace_object_allocations"><code>::trace_object_allocations</code></a> for more information and examples.</p>

<p>If <em>since</em> is omitted or is <code>nil</code>, all objects are dumped.</p>

<p><em>shapes</em> must be a boolean or a non-negative integer.</p>

<p>If <em>shapes</em> is a positive integer, only shapes newer than the provided shape id are dumped. The current shape_id can be accessed using <code>RubyVM.stat(:next_shape_id)</code>.</p>

<p>If <em>shapes</em> is <code>false</code>, no shapes are dumped.</p>

<p>To only dump objects allocated past a certain point you can combine <em>since</em> and <em>shapes</em>:</p>

<pre class="ruby"><span class="ruby-constant">ObjectSpace</span>.<span class="ruby-identifier">trace_object_allocations</span>
<span class="ruby-constant">GC</span>.<span class="ruby-identifier">start</span>
<span class="ruby-identifier">gc_generation</span> = <span class="ruby-constant">GC</span>.<span class="ruby-identifier">count</span>
<span class="ruby-identifier">shape_generation</span> = <span class="ruby-constant">RubyVM</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-value">:next_shape_id</span>)
<span class="ruby-identifier">call_method_to_instrument</span>
<span class="ruby-constant">ObjectSpace</span>.<span class="ruby-identifier">dump_all</span>(<span class="ruby-value">since:</span> <span class="ruby-identifier">gc_generation</span>, <span class="ruby-value">shapes:</span> <span class="ruby-identifier">shape_generation</span>)
</pre>

<p>This method is only expected to work with C Ruby. This is an experimental method and is subject to change. In particular, the function signature and output format are not guaranteed to be compatible in future versions of ruby.</p>

                              <div class="method-source-code" id="dump_all-source">
            <pre><span class="ruby-comment"># File objspace/lib/objspace.rb, line 84</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">dump_all</span>(<span class="ruby-value">output:</span> <span class="ruby-value">:file</span>, <span class="ruby-value">full:</span> <span class="ruby-keyword">false</span>, <span class="ruby-value">since:</span> <span class="ruby-keyword">nil</span>, <span class="ruby-value">shapes:</span> <span class="ruby-keyword">true</span>)
  <span class="ruby-identifier">out</span> = <span class="ruby-keyword">case</span> <span class="ruby-identifier">output</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">:file</span>, <span class="ruby-keyword">nil</span>
    <span class="ruby-identifier">require</span> <span class="ruby-string">&#39;tempfile&#39;</span>
    <span class="ruby-constant">Tempfile</span>.<span class="ruby-identifier">create</span>(<span class="ruby-node">%w(rubyheap .json)</span>)
  <span class="ruby-keyword">when</span> <span class="ruby-value">:stdout</span>
    <span class="ruby-constant">STDOUT</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">:string</span>
    <span class="ruby-string">+&#39;&#39;</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">IO</span>
    <span class="ruby-identifier">output</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;wrong output option: #{output.inspect}&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">shapes</span> = <span class="ruby-value">0</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">shapes</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">true</span>
  <span class="ruby-identifier">ret</span> = <span class="ruby-identifier">_dump_all</span>(<span class="ruby-identifier">out</span>, <span class="ruby-identifier">full</span>, <span class="ruby-identifier">since</span>, <span class="ruby-identifier">shapes</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">output</span> <span class="ruby-operator">==</span> <span class="ruby-value">:stdout</span>
  <span class="ruby-identifier">ret</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-dump_shapes" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">dump_shapes</span><span
                                class="method-args">(output: :file, since: 0)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Dump the contents of the ruby shape tree as JSON.</p>

<p><em>output</em> argument is the same as for <a href="ObjectSpace.html#method-i-dump"><code>dump</code></a>.</p>

<p>If <em>since</em> is a positive integer, only shapes newer than the provided shape id are dumped. The current shape_id can be accessed using <code>RubyVM.stat(:next_shape_id)</code>.</p>

<p>This method is only expected to work with C Ruby. This is an experimental method and is subject to change. In particular, the function signature and output format are not guaranteed to be compatible in future versions of ruby.</p>

                              <div class="method-source-code" id="dump_shapes-source">
            <pre><span class="ruby-comment"># File objspace/lib/objspace.rb, line 116</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">dump_shapes</span>(<span class="ruby-value">output:</span> <span class="ruby-value">:file</span>, <span class="ruby-value">since:</span> <span class="ruby-value">0</span>)
  <span class="ruby-identifier">out</span> = <span class="ruby-keyword">case</span> <span class="ruby-identifier">output</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">:file</span>, <span class="ruby-keyword">nil</span>
    <span class="ruby-identifier">require</span> <span class="ruby-string">&#39;tempfile&#39;</span>
    <span class="ruby-constant">Tempfile</span>.<span class="ruby-identifier">create</span>(<span class="ruby-node">%w(rubyshapes .json)</span>)
  <span class="ruby-keyword">when</span> <span class="ruby-value">:stdout</span>
    <span class="ruby-constant">STDOUT</span>
  <span class="ruby-keyword">when</span> <span class="ruby-value">:string</span>
    <span class="ruby-string">+&#39;&#39;</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">IO</span>
    <span class="ruby-identifier">output</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;wrong output option: #{output.inspect}&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">ret</span> = <span class="ruby-identifier">_dump_shapes</span>(<span class="ruby-identifier">out</span>, <span class="ruby-identifier">since</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">output</span> <span class="ruby-operator">==</span> <span class="ruby-value">:stdout</span>
  <span class="ruby-identifier">ret</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is a service of <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>, purveyors of fine <a href='https://jamesbritt.bandcamp.com/'>dance noise</a></p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

